package bar.dark.lee.alarm;

import bar.dark.lee.alarm.main.MainActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;

public class IntroActivity extends SuperActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.intro_activity);
        
        setGoneTitle();
    }
    
    @Override
    protected void onResume()
    {
    	super.onResume();
    	
    	new ShowDialog().execute(0);
    }
    
    /**
	 * 메인으로
	 */
	private void goMain() 
	{
		Intent intent = new Intent(IntroActivity.this, MainActivity.class);
		intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
		startActivity(intent);
		finish();
		overridePendingTransition(R.anim.right_in, R.anim.left_out);
	}
	
	/**
	 * 다이얼로그 뛰우기 
	 */
	private class ShowDialog extends AsyncTask<Integer, Integer, Integer>{
		ProgressDialog dialog = null;
		@Override
		protected void onPreExecute() {
			super.onPreExecute();
			dialog = new ProgressDialog(IntroActivity.this);
			dialog.setCancelable(false);
			dialog.setMessage("Loading...");
			dialog.show();
		}
		
		@Override
		protected Integer doInBackground(Integer... arg0) {
			if (arg0[0] == 0)
			{
				DBInit init = new DBInit(superContext);
				init.setTable(superContext);
				return 0;
			}

			return -1;
		}
		
		@Override
		protected void onPostExecute(Integer result) {
			super.onPostExecute(result);

			if (dialog != null) {
				dialog.dismiss();
			}
			
			if (result == 0)
			{
				 goMain();
			}
		}
	}

	@Override
	public void setFindView()
	{
	}

	@Override
	public void setDataSetting()
	{
	}

	@Override
	public void setClickListener()
	{
	}

	@Override
	protected void tipButton()
	{
	}
}